﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Ccit.OA.MsQuestion;

namespace Ccit.OA.Question
{
    public partial class qst_statistics_view : Ccit.Utils.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ViewState["MSGIDS"] = "";
                _hidsRecid.Value = (null != Request.QueryString["Id"]) ? Request.QueryString["Id"].ToString() : "0";                 
                InitPage(); 
            } 
        }
        /// <summary>
        /// 初始化页面数据
        /// </summary>
        private void InitPage()
        {
            if (_hidsRecid.Value != "0")
            {
                QuestionBLL Bll = new QuestionBLL();
                MsQuestionMes msMes = Bll.GetQuestions(_hidsRecid.Value.ToString()); 
                if (msMes != null)
                {
                    lblTitle.Text = msMes.title;
                    lblEndTime.Text = (msMes.endtime!="")?msMes.endtime:"&nbsp;";
                    lblExplain.Text = (msMes.explain != "") ? msMes.explain : "&nbsp;";
                    lblType.Text = (msMes.type == "0") ? "匿名" : "实名";
                    lblAll.Text = msMes.ucount;
                    lblCount.Text = msMes.typename;
                    int nCount = int.Parse(msMes.ucount) - int.Parse(msMes.typename);
                    lblNotCount.Text = nCount.ToString();
                }
                Bll = null;
                Create();
            }
        }
        private void Create()
        {
            QuestionBLL Bll = new QuestionBLL();
            string Options = Bll.GetOptionsMessage(_hidsRecid.Value);
            DataSet dSet = Bll.GetQuestion(_hidsRecid.Value, "3");
            if (dSet.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < dSet.Tables[0].Rows.Count; i++)
                {
                    DataRow dRow = dSet.Tables[0].Rows[i];
                    if (dRow["Qst_A2_10"].ToString()!="")
                        CreateTable(i, dRow, Options); 
                }
            }
            Bll = null;
        }

        private void CreateTable(int i, DataRow dRow, string Options)
        {
            int iLine = i;
            HtmlTableRow oRow = new HtmlTableRow();
            oRow.ID = "row_" + iLine.ToString();
            oRow.Attributes["class"] = "listrow2";

            HtmlTableCell oCellM = new HtmlTableCell();
            oCellM.Align = "left";
            oCellM.ColSpan = 2;
            string stype = "多选";
            if (dRow["Qst_A2_50"].ToString() == "0")
            {
                stype = "单选";
            }
            HtmlInputHidden hidden = new HtmlInputHidden();
            hidden.Value = dRow["Qst_A2_10"].ToString();
            oCellM.Attributes["class"] = "listrow2";
            oCellM.Attributes["width"] = "8%";
            oCellM.InnerHtml = "<nobr>" + (i + 1).ToString() + "、" + dRow["Qst_A2_30"].ToString() + "(" + stype + ")</nobr>";
            oCellM.Controls.Add(hidden);
            oRow.Cells.Add(oCellM);
            if (dRow["Qst_A2_60"].ToString() == "1")
            { 
                HtmlTableCell oCellQT = new HtmlTableCell();
                oCellQT.Align = "left"; 
                oCellQT.Attributes["width"] = "10%";
                oCellQT.InnerHtml = "<a href=\"javascript:doView(" + _hidsRecid.Value + "," + dRow["Qst_A2_10"].ToString() + ",'')\">";
                oCellQT.InnerHtml += "其他意见>>></a>";
                oRow.Cells.Add(oCellQT);
            }
            tbProduct.Rows.Add(oRow); 
            QuestionBLL Bll = new QuestionBLL();
            DataSet dSetX = Bll.GetQuestion(dRow["Qst_A2_10"].ToString(), "1"); 
            if (dSetX.Tables[0].Rows.Count > 0)
            {
                
                for (int j = 0; j < dSetX.Tables[0].Rows.Count; j++)
                {
                    HtmlTableRow oRow1 = new HtmlTableRow();
                    DataRow dRowx = dSetX.Tables[0].Rows[j]; 
                    HtmlTableCell oCellX = new HtmlTableCell();
                    oCellX.Align = "center";
                    oCellX.Width = "20%";
                   
                    //oCellX.InnerHtml = "<a href=\"javascript:doView('"+dRow["Qst_A2_10"].ToString()+"'," + dRowx["Qst_A3_10"].ToString() + ")\">";
                    oCellX.InnerHtml = "<nobr>" + dRowx["Qst_A3_40"].ToString() + "</nobr>";
                    oRow1.Cells.Add(oCellX);
                    DataSet ObjdSet = Bll.GetQuestionsCount(_hidsRecid.Value, dRowx["Qst_A3_10"].ToString());
                    if (ObjdSet.Tables[0].Rows.Count > 0)
                    { 
                        HtmlTableCell oCellH = new HtmlTableCell();
                        oCellH.Align = "left";
                        oCellH.Width = "50%";
                        string iCount = "0"; 
                        string str = ObjdSet.Tables[0].Rows[0][2].ToString();
                        int iLen = 0; 
                        string[] iLen1 = Options.Split(',');
                         
                        for (int k = 0; k < iLen1.Length; k++)
                        {
                            if (ObjdSet.Tables[0].Rows[0][0].ToString() != iLen1[k].ToString())
                            {
                                iCount = "0";
                                iLen = 0;
                            }
                            else
                            {
                                iLen = int.Parse(ObjdSet.Tables[0].Rows[0][1].ToString()) * 100 / int.Parse(lblCount.Text);
                                iCount = ObjdSet.Tables[0].Rows[0][1].ToString(); 
                                break;
                            }
                        }
                        
                        oCellH.InnerHtml = "<hr align='left' size='5' width=" + iLen+ "%  color='#EC8D00'>";
                        oRow1.Cells.Add(oCellH);
                        HtmlTableCell oCellC = new HtmlTableCell();
                        oCellC.Width = "30%";
                        oCellC.Align = "left";
                        oCellC.InnerHtml = "(" + iCount + "人) " + iLen + "%";
                        oRow1.Cells.Add(oCellC); 
                    }
                    tbProduct.Rows.Add(oRow1);
                }
            }
        }
    }
}
